import numpy as np


def edit_distance(string1, string2):
    len1 = len(string1)
    len2 = len(string2)

    buffer = np.zeros((len1 + 1, len2 + 1), dtype=np.int32)

    for i in range(len1 + 1):
        buffer[i][len2] = len1 - i
    for i in range(len2 + 1):
        buffer[len1][i] = len2 - i

    for i in reversed(range(len1)):
        for j in reversed(range(len2)):
            buffer[i][j] = min(
                int(string1[i] != string2[j]) + buffer[i + 1][j + 1],   # not modified / replace
                1 + buffer[i + 1][j],                                   # delete
                1 + buffer[i][j + 1]                                    # insert
            )

    return buffer[0][0]
